package demo.spring.securing;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;

import javax.sql.DataSource;

/**
 * 用户身份认证
 * 用户授权
 * <p>
 * Created by chenlushun on 2016/12/8.
 */
@SpringBootApplication
public class SecuringApplication {
    public static void main(String[] args) {
        SpringApplication.run(SecuringApplication.class, args);
    }

//    @Bean
//    public UserDetailsService userDetailsService() throws Exception {
//        InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
//        manager.createUser(User.withUsername("user").password("password").roles("USER").build());
//        manager.createUser(User.withUsername("admin").password("password").roles("USER", "ADMIN").build());
//        return manager;
//    }

    @Bean
    public SecuritySettings securitySettings() {
        return new SecuritySettings();
    }

    @Autowired
    @Qualifier("dataSource")
    private DataSource dataSource;

    @Bean
    public JdbcTokenRepositoryImpl tokenRepository() {
        JdbcTokenRepositoryImpl jpi = new JdbcTokenRepositoryImpl();
        //jpi.setDataSource(dataSource);
        return jpi;
    }

}
